﻿<UserControl x:Class="Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views.CodeMetricsCalculationResultContent"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local.views="clr-namespace:Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views"
             xmlns:local.converters="clr-namespace:Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views.Converters"
             xmlns:local.controls="clr-namespace:Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="300"
             d:DesignWidth="600">
    <UserControl.Resources>
        <local.converters:DoubleToDataGridLengthConverter x:Key="doubleToDataGridLengthConverter"/>
    </UserControl.Resources>
    <Grid Name="layoutRoot" MinWidth="500" FocusManager.FocusedElement="{Binding ElementName=resultDataGrid}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <local.controls:ToolBar Grid.Row="0"/>
        <DataGrid Name="resultDataGrid" Grid.Row="1" ItemsSource="{Binding CurrentPageRows}" IsSynchronizedWithCurrentItem="True" IsReadOnly="True" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserSortColumns="True" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" Sorting="OnSortRows">
            <DataGrid.Resources>
                <Style x:Key="cellStyle" TargetType="TextBlock">
                    <Setter Property="TextWrapping" Value="WrapWithOverflow"/>
                    <Setter Property="Margin" Value="2"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
                <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"/>
            </DataGrid.Resources>
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Show Columns">
                        <MenuItem Header="Name" IsCheckable="True" IsChecked="{Binding Grid.Name.IsVisible}"/>
                        <MenuItem Header="MI" IsCheckable="True" IsChecked="{Binding Grid.MaintainabilityIndex.IsVisible}"/>
                        <MenuItem Header="CC" IsCheckable="True" IsChecked="{Binding Grid.CyclomaticComplexity.IsVisible}"/>
                        <MenuItem Header="CCP" IsCheckable="True" IsChecked="{Binding Grid.ClassCoupling.IsVisible}"/>
                        <MenuItem Header="LOC" IsCheckable="True" IsChecked="{Binding Grid.LinesOfCode.IsVisible}"/>
                        <MenuItem Header="DOI" IsCheckable="True" IsChecked="{Binding Grid.DepthOfInheritance.IsVisible}"/>
                    </MenuItem>
                    <MenuItem Header="Reset Columns" Click="OnResetColumns"/>
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.ItemContainerStyle>
                <Style TargetType="DataGridRow">
                    <EventSetter Event="MouseDoubleClick" Handler="OnRowDoubleClicked" />
                    <Setter Property="ToolTipService.ShowDuration" Value="60000"/>
                    <Setter Property="ToolTip">
                        <Setter.Value>
                            <ToolTip>
                                <StackPanel>
                                    <StackPanel Orientation="Horizontal">
                                        <StackPanel.Style>
                                            <Style TargetType="StackPanel">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding ProjectName}" Value="{x:Null}">
                                                        <Setter Property="Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </StackPanel.Style>
                                        <TextBlock FontWeight="Bold">Project :</TextBlock>
                                        <TextBlock FontWeight="Bold" Text="{Binding ProjectName}" Margin="5,0"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5">
                                        <StackPanel.Style>
                                            <Style TargetType="StackPanel">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding AssemblyName}" Value="{x:Null}">
                                                        <Setter Property="Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </StackPanel.Style>
                                        <Image Source="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Assembly.png"/>
                                        <TextBlock Text="{Binding AssemblyName}" Margin="5,0"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="15,2,0,2">
                                        <StackPanel.Style>
                                            <Style TargetType="StackPanel">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Namespace}" Value="{x:Null}">
                                                        <Setter Property="Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </StackPanel.Style>
                                        <Image Source="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Namespace.png"/>
                                        <TextBlock Text="{Binding Namespace}" Margin="5,0"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="30,2,0,2">
                                        <StackPanel.Style>
                                            <Style TargetType="StackPanel">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding TypeName}" Value="{x:Null}">
                                                        <Setter Property="Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </StackPanel.Style>
                                        <Image Source="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Class.png"/>
                                        <TextBlock Text="{Binding TypeName}" Margin="5,0"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="45,2,0,2">
                                        <StackPanel.Style>
                                            <Style TargetType="StackPanel">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Signature}" Value="{x:Null}">
                                                        <Setter Property="Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </StackPanel.Style>
                                        <Image Source="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Method.png"/>
                                        <TextBlock Text="{Binding Signature}" Margin="5,0"/>
                                    </StackPanel>
                                    <TextBlock Margin="0,10,0,0">
                                        <TextBlock.Style>
                                            <Style TargetType="TextBlock">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Kind}" Value="Module">
                                                        <Setter Property="Text" Value="Double-click to drill down into this assembly."/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Kind}" Value="Namespace">
                                                        <Setter Property="Text" Value="Double-click to drill down into this namespace."/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Kind}" Value="Type">
                                                        <Setter Property="Text" Value="Double-click to drill down into this type."/>
                                                    </DataTrigger>
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding Kind}" Value="Member"/>
                                                            <Condition Binding="{Binding CanFocusSourceCode}" Value="True"/>
                                                        </MultiDataTrigger.Conditions>
                                                        <MultiDataTrigger.Setters>
                                                            <Setter Property="Text" Value="Double-click to focus source code of this member."/>
                                                        </MultiDataTrigger.Setters>
                                                    </MultiDataTrigger>
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding Kind}" Value="Member"/>
                                                            <Condition Binding="{Binding CanFocusSourceCode}" Value="False"/>
                                                        </MultiDataTrigger.Conditions>
                                                        <MultiDataTrigger.Setters>
                                                            <Setter Property="Visibility" Value="Collapsed"/>
                                                        </MultiDataTrigger.Setters>
                                                    </MultiDataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>
                                </StackPanel>
                            </ToolTip>
                        </Setter.Value>
                    </Setter>
                </Style>
            </DataGrid.ItemContainerStyle>
            <DataGrid.Columns>
                <DataGridTemplateColumn x:Name="kindColumn" Header="" IsReadOnly="True" SortMemberPath="Kind" CanUserResize="False" CanUserReorder="False" Width="25">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Margin="5">
                                <Image.Style>
                                    <Style TargetType="Image">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Kind}" Value="Module">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Assembly.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Namespace">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Namespace.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Type">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Class.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Member">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Method.png"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="nameColumn" Header="Name" IsReadOnly="True" SortMemberPath="Name"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.Name.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.Name.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="maintainabilityIndexColumn" IsReadOnly="True" SortMemberPath="MaintainabilityIndex"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.MaintainabilityIndex.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.MaintainabilityIndex.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="MI" ToolTipService.ShowDuration="60000">
                                <TextBlock.ToolTip>
                                    <StackPanel Margin="5" Width="350">
                                        <TextBlock FontWeight="Bold">Maintainability Index (MI)</TextBlock>
                                        <TextBlock TextWrapping="WrapWithOverflow" Margin="5">The Maintainability Index is a combination of several metrics, including Cyclomatic Complexity and Average Lines of Code, as well as computational complexity, based off the Halstead Volume function. The maintainability index is a value between 1 and 100 and a high value means better maintainability (the easier your code will be to maintain).</TextBlock>
                                    </StackPanel>
                                </TextBlock.ToolTip>
                            </TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding MaintainabilityIndex}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="cyclomaticComplexityColumn" IsReadOnly="True" SortMemberPath="CyclomaticComplexity"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.CyclomaticComplexity.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.CyclomaticComplexity.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="CC" ToolTipService.ShowDuration="60000">
                                <TextBlock.ToolTip>
                                    <StackPanel Margin="5" Width="350">
                                        <TextBlock FontWeight="Bold">Cyclomatic Complexity (CC)</TextBlock>
                                        <TextBlock TextWrapping="WrapWithOverflow" Margin="5">Cyclomatic complexity represents the number of unique paths through your code. More simply, it's the number of "if" statements, loops and switch cases in your code. Code with a high cyclomatic complexity can be hard to test and maintain, as there are a number of different paths through the code that must be tested. For Cyclomatic Complexity, a low value is good and a high value is bad.</TextBlock>
                                    </StackPanel>
                                </TextBlock.ToolTip>                            
                            </TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CyclomaticComplexity}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="classCouplingColumn" IsReadOnly="True" SortMemberPath="ClassCoupling"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.ClassCoupling.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.ClassCoupling.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="CCP" ToolTipService.ShowDuration="60000">
                                <TextBlock.ToolTip>
                                    <StackPanel Margin="5" Width="350">
                                        <TextBlock FontWeight="Bold">Class Coupling (CCP)</TextBlock>
                                        <TextBlock TextWrapping="WrapWithOverflow" Margin="5">Class coupling is a measure of the dependencies a class has on other classes. This dependency is measured through parameters, method calls and interface implementations, just to name a few. The higher this number, the more likely a change in one class will affect other classes. For class coupling, a low value is good and a high value is bad.</TextBlock>
                                    </StackPanel>
                                </TextBlock.ToolTip>
                            </TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ClassCoupling}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="linesOfCodeColumn" IsReadOnly="True" SortMemberPath="LinesOfCode"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.LinesOfCode.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.LinesOfCode.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="LOC" ToolTipService.ShowDuration="60000">
                                <TextBlock.ToolTip>
                                    <StackPanel Margin="5" Width="350">
                                        <TextBlock FontWeight="Bold">Lines Of Code (LOC)</TextBlock>
                                        <TextBlock TextWrapping="WrapWithOverflow" Margin="5">Lines of Code indicates the number of executable lines of code in a method. This count is an approximate number, based on the Intermediate Langauge (IL) code. It includes only executable lines of code, so comments, braces, white space and member declarations are excluded. As you would expect, the more lines of code in your application, the more code there is to maintain. For Lines of Code, a low value is good and a high value is bad.</TextBlock>
                                    </StackPanel>
                                </TextBlock.ToolTip>                            
                            </TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding LinesOfCode}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="depthOfInheritanceColumn" IsReadOnly="True" SortMemberPath="DepthOfInheritance"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.DepthOfInheritance.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.DepthOfInheritance.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="DOI" ToolTipService.ShowDuration="60000">
                                <TextBlock.ToolTip>
                                    <StackPanel Margin="5" Width="350">
                                        <TextBlock FontWeight="Bold">Depth Of Inheritance (DOI)</TextBlock>
                                        <TextBlock TextWrapping="WrapWithOverflow" Margin="5">Depth of Inheritance indicates the number of different classes that inherit from one another, all the way back to the base class. Depth of Inheritance is similar to class coupling in that a change in a base class can affect any of its inherited classes. The higher this number, the deeper the depth of inheritance and the more potential for causing breaking changes in your code when modifying a base class. For Depth of Inheritance, a low value is good and a high value is bad.</TextBlock>
                                    </StackPanel>
                                </TextBlock.ToolTip>
                            </TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding DepthOfInheritance}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        <Grid Grid.Row="2" Margin="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" VerticalAlignment="Center">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0} metric values matched (total {1} metric values)">
                        <Binding Path="Count"/>
                        <Binding Path="Rows.Count"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <local.controls:Pager Grid.Column="1"/>
        </Grid>
    </Grid>
</UserControl>
